<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Updatedatacron extends CI_Controller{ 
	public function update(){
		// 1. truncate table
		// 2. get phones from api
		$tbl_phones = "DummyPhones";
		$this->db->truncate($tbl_phones);
		$this->load->model("device");

		$gadgetsFromAPI = $this->device->getPhonesFromAPI();


		// db initialize
		// $this->load->database();
		$dataArr = array();
			foreach($gadgetsFromAPI as $gadget) {
				$data['gadgetId'] = $gadget->gadgetId;
				$data['gadgetName'] = $gadget->gadgetName;
				$data['gadgetBrand'] = $gadget->gadgetBrand;
				$data['gadgetPrice'] = $gadget->gadgetPrice;
				$data['gadgetPlanPrice'] = $gadget->gadgetPlanPrice;
				$data['gadgetSKU'] = $gadget->gadgetSKU;
				$data['gadgetImage'] = $gadget->gadgetImage;				
				array_push($dataArr, $data);
			}
			//$this->db = $CI->db;
			$this->db->insert_batch($tbl_phones, $dataArr); 
	}	
}